/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.impl;

import ar.edu.utn.frsf.cidisi.upcolbpip.b2bcollaborations.PartnerRole;

import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionprotocolsPackage;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.Lifeline;
import ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.Role;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Role</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.RoleImpl#getName <em>Name</em>}</li>
 *   <li>{@link ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.RoleImpl#getRoleLifeline <em>Role Lifeline</em>}</li>
 *   <li>{@link ar.edu.utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.RoleImpl#getRolePartnerRole <em>Role Partner Role</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RoleImpl extends EObjectImpl implements Role {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getRoleLifeline() <em>Role Lifeline</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRoleLifeline()
	 * @generated
	 * @ordered
	 */
	protected Lifeline roleLifeline;

	/**
	 * The cached value of the '{@link #getRolePartnerRole() <em>Role Partner Role</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRolePartnerRole()
	 * @generated
	 * @ordered
	 */
	protected PartnerRole rolePartnerRole;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected RoleImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return InteractionprotocolsPackage.Literals.ROLE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.ROLE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Lifeline getRoleLifeline() {
		return roleLifeline;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetRoleLifeline(Lifeline newRoleLifeline, NotificationChain msgs) {
		Lifeline oldRoleLifeline = roleLifeline;
		roleLifeline = newRoleLifeline;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.ROLE__ROLE_LIFELINE, oldRoleLifeline, newRoleLifeline);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRoleLifeline(Lifeline newRoleLifeline) {
		if (newRoleLifeline != roleLifeline) {
			NotificationChain msgs = null;
			if (roleLifeline != null)
				msgs = ((InternalEObject)roleLifeline).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - InteractionprotocolsPackage.ROLE__ROLE_LIFELINE, null, msgs);
			if (newRoleLifeline != null)
				msgs = ((InternalEObject)newRoleLifeline).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - InteractionprotocolsPackage.ROLE__ROLE_LIFELINE, null, msgs);
			msgs = basicSetRoleLifeline(newRoleLifeline, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.ROLE__ROLE_LIFELINE, newRoleLifeline, newRoleLifeline));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PartnerRole getRolePartnerRole() {
		if (rolePartnerRole != null && rolePartnerRole.eIsProxy()) {
			InternalEObject oldRolePartnerRole = (InternalEObject)rolePartnerRole;
			rolePartnerRole = (PartnerRole)eResolveProxy(oldRolePartnerRole);
			if (rolePartnerRole != oldRolePartnerRole) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, InteractionprotocolsPackage.ROLE__ROLE_PARTNER_ROLE, oldRolePartnerRole, rolePartnerRole));
			}
		}
		return rolePartnerRole;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PartnerRole basicGetRolePartnerRole() {
		return rolePartnerRole;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setRolePartnerRole(PartnerRole newRolePartnerRole) {
		PartnerRole oldRolePartnerRole = rolePartnerRole;
		rolePartnerRole = newRolePartnerRole;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.ROLE__ROLE_PARTNER_ROLE, oldRolePartnerRole, rolePartnerRole));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case InteractionprotocolsPackage.ROLE__ROLE_LIFELINE:
				return basicSetRoleLifeline(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case InteractionprotocolsPackage.ROLE__NAME:
				return getName();
			case InteractionprotocolsPackage.ROLE__ROLE_LIFELINE:
				return getRoleLifeline();
			case InteractionprotocolsPackage.ROLE__ROLE_PARTNER_ROLE:
				if (resolve) return getRolePartnerRole();
				return basicGetRolePartnerRole();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case InteractionprotocolsPackage.ROLE__NAME:
				setName((String)newValue);
				return;
			case InteractionprotocolsPackage.ROLE__ROLE_LIFELINE:
				setRoleLifeline((Lifeline)newValue);
				return;
			case InteractionprotocolsPackage.ROLE__ROLE_PARTNER_ROLE:
				setRolePartnerRole((PartnerRole)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case InteractionprotocolsPackage.ROLE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case InteractionprotocolsPackage.ROLE__ROLE_LIFELINE:
				setRoleLifeline((Lifeline)null);
				return;
			case InteractionprotocolsPackage.ROLE__ROLE_PARTNER_ROLE:
				setRolePartnerRole((PartnerRole)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case InteractionprotocolsPackage.ROLE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case InteractionprotocolsPackage.ROLE__ROLE_LIFELINE:
				return roleLifeline != null;
			case InteractionprotocolsPackage.ROLE__ROLE_PARTNER_ROLE:
				return rolePartnerRole != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //RoleImpl
